package cn.li.security.controller;


import cn.li.security.jwt.service.IJwtService;
import cn.li.security.jwt.service.JwtResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/account")
public class AccountController {

    @GetMapping("")
    public UserDetails get(@AuthenticationPrincipal UserDetails userDetails){
        return userDetails;
    }

    @Autowired
    private IJwtService jwtService;

    @GetMapping("/refresh")
    public JwtResult refresh(@AuthenticationPrincipal UserDetails userDetails){
        return jwtService.generator(userDetails);
    }
}
